package edu.hrbu.spring.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * @author 徐登宇
 */
public class User implements BeanNameAware,
        BeanClassLoaderAware,
        BeanFactoryAware,
        InitializingBean,
        DisposableBean {

    private String name;

    public User() {
        System.out.println("生命周期第一步：实例化bean");
    }

    public void setName(String name) {
        System.out.println("生命周期第二步：给bean属性赋值");
        this.name = name;
    }

    public void initUser() {
        System.out.println("生命周期第四步：初始化bean");
    }

    public void destroyUser() {
        System.out.println("生命周期第七步：销毁bean");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("[User] 类加载器：" + classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("[User] bean工厂：" + beanFactory);
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("[User] bean的name：" + s);
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("[User] DisposableBean's destory()");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("[User] InitializingBean's afterPropertiesSet()");
    }
}
